package com.xw.bo.ks.util;

import com.xw.bo.ks.entity.base.DayCompareBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalUnit;
import java.util.*;

/**
 * DateUtil工具类
 *
 * @author taoruicheng
 * @date 2019-10-12 14:34
 */
public final class DateUtils {

    private static final Logger logger = LoggerFactory.getLogger(DateUtils.class);

    public static final String DATE_PATTERN_DEFAULT = "yyyy-MM-dd HH:mm:ss";

    public static final String DATE_PATTERN_1 = "yyyy_MM_dd";

    public static final String DATE_PATTERN_yyyy_MM_dd_HH = "yyyy_MM_dd_HH";

    public static final String DATE_PATTERN_TABLE = "yyyy_M";

    public static final String DATE_PATTERN_MONTH = "yyyy_MM";

    /**
     * 年月日时分秒
     */
    public static final String DATE_FORMAT_yyyyMMddHHmmss = "yyyyMMddHHmmss";
    public static final String DATE_FORMAT_yyyyMMddHHmmss_H = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_FORMAT_yyyyMMddHHmmss_CN = "yyyy年MM月dd日 HH:mm:ss";

    public static final String DATE_FORMAT_yyyyMMddHHmm = "yyyyMMddHHmm";
    public static final String DATE_FORMAT_yyyyMMddHHmm_H = "yyyy-MM-dd HH:mm";
    public static final String DATE_FORMAT_yyyyMMddHHmm_CN = "yyyy年MM月dd日 HH:mm";

    /*年月日时分*/
    public static final String DATE_FORMAT_MMddHHmm = "yyyyMMddHHmm";
    public static final String DATE_FORMAT_MMddHHmm_H = "MM-dd HH:mm";
    public static final String DATE_FORMAT_MMddHHmm_CN = "MM月dd日 HH:mm";

    /*年月日*/
    public static final String DATE_FORMAT_yyyyMMdd = "yyyyMMdd";
    public static final String DATE_FORMAT_yyyyMMdd_H = "yyyy-MM-dd";
    public static final String DATE_FORMAT_yyyyMMdd_CN = "yyyy年MM月dd日";

    /*月日*/
    public static final String DATE_FORMAT_MMdd = "MMdd";
    public static final String DATE_FORMAT_MMdd_H = "MM-dd";
    public static final String DATE_FORMAT_MMdd_CN = "MM月dd日";

    /*时分秒*/
    public static final String DATE_FORMAT_HHmmss = "HHmmss";
    public static final String DATE_FORMAT_HHmmss_H = "HH:mm:ss";

    public static final String DATE_FORMAT_yyyyMMddHHmmssSSS = "yyyyMMddHHmmssSSS";
    public static final String DATE_FORMAT_yyyyMMddHHmmss_UTC = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'";
    public static final String DATE_FORMAT_yyyyMMddHHmmssSSS_UTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";

    public static final ZoneId ZONEID_SHANGHAI = ZoneId.of("Asia/Shanghai");

    public static final long DAY_PARSE_LONG_TIME = 86400000L;


    /**
     * 格式化日期格式
     *
     * @param time 时间,要求有毫秒
     * @return 字符串
     */
    public static String formatDateByNumber(long time) {
        return formatDateToString(new Date(time), DATE_PATTERN_DEFAULT);
    }

    /**
     * 格式化日期格式
     *
     * @param time 时间
     * @return 格式化时间
     */
    public static String formatYyyyMMddHHmmss(Long time) {
        return formatDateToString(new Date(time), DATE_FORMAT_yyyyMMddHHmmss);
    }

    public static String formatDateByNumber(long time, String pattern) {
        return formatDateToString(new Date(time), pattern);
    }

    public static String formatDateByNumberString(String time) {
        try {
            Long t = Long.parseLong(time);
            return formatDateByNumber(t);
        } catch (NumberFormatException numberFormatException) {
            return time;
        }
    }

    public static String formatDateNow() {
        Long t = getNowDate().getTime();
        return formatDateByNumber(t);
    }

    /**
     * 格式化日期格式
     *
     * @param date
     * @return
     */
    public static String getDateString(Date date) {
        return getDateString(date, DATE_PATTERN_DEFAULT);
    }

    /**
     * 格式化日期格式
     *
     * @param date
     * @param pattern
     * @return
     */
    public static String getDateString(Date date, String pattern) {
        String dateStr = "";
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
            dateStr = simpleDateFormat.format(date);
        } catch (Exception e) {
            logger.error("get date string failed", e);
        }
        return dateStr;
    }


    /**
     * 将ISO_DATE格式字符串转为LocalDate
     * ISO_DATE such as '2011-12-03' or '2011-12-03+01:00'
     *
     * @param localDateText 格式 such as '2011-12-03' or '2011-12-03+01:00',not null
     * @return LocalDate
     */
    public static LocalDate parseLocalDate(String localDateText) {
        return LocalDate.parse(localDateText, DateTimeFormatter.ISO_DATE);
    }

    /**
     * 将ISO_LOCAL_TIME 格式字符串转为LocalTime
     * ISO_LOCAL_TIME such as '10:15:30' or '10:15'
     *
     * @param localTimeText 格式such as '10:15:30' or '10:15'，not null
     * @return
     */
    public static LocalTime parseLocalTime(String localTimeText) {
        return LocalTime.parse(localTimeText);
    }

    /**
     * 将 localDateTimeText 字符串 按照 datePattern 格式转为LocalDateTime 日期对象
     * datePattern
     *
     * @param localDateTimeText 带解析日期字符串，必须包含   年月日时分秒
     * @param datePattern       解析日期的格式 必须包含年月日时分秒格式
     * @return LocalDateTime
     */
    public static LocalDateTime parse(String localDateTimeText, String datePattern) {
        return LocalDateTime.parse(localDateTimeText, DateTimeFormatter.ofPattern(datePattern));
    }

    /**
     * 将字符串日期按照format格式转为Date
     *
     * @param date   日期字符串
     * @param format
     * @return
     */
    public static Date parseStringToDate(String date, String format) {
        Date result = parseStrToDate(date,format);
        if (null == result){
            logger.error(" parse {} to date error.", date);
        }
        return result;
    }

    public static Date parseStrToDate(String date, String format) {
        Date result;
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
            result = simpleDateFormat.parse(date);
        } catch (ParseException e) {
            return null;
        }
        return result;
    }

    /**
     * 将日期字符串按照format格式获取日期毫秒数
     *
     * @param date   日期字符串
     * @param format
     * @return
     */
    public static Long parseStringToLong(String date, String format) {
        Long result = parseStrToLong(date,format);
        if (null == result){
            logger.error(" parse {} to date error.", date);
        }
        return result;
    }

    public static Long parseStrToLong(String date, String format) {
        long result;
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
            result = simpleDateFormat.parse(date).getTime();
        } catch (ParseException e) {
            return null;
        }
        return result;
    }

    /**
     * 获取下个周日的LocalDate
     *
     * @param date localDate
     * @return 下个周日的LocalDate
     */
    public static LocalDate getLocalDateNextSunday(LocalDate date) {
        return date.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
    }


    /**
     * 获得指定LocalDateTime的毫秒数
     *
     * @param localDateTime
     * @return 毫秒数
     */
    public static Long getMilliByTime(LocalDateTime localDateTime) {
        return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    /**
     * 获取指定LocalDateTime的Java纪元的秒数
     *
     * @param time
     * @return Java纪元的秒数
     */
    public static Long getSecondsByTime(LocalDateTime time) {
        return time.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
    }

    /**
     * 获取 yyyy-MM-dd HH:mm:ss 格式time   最近 count 分钟的日期，并以转换为 datePattern格式字符串List返回
     *
     * @param count       最近 count 分钟
     * @param time        yyyy-MM-dd HH:mm:ss 格式time
     * @param datePattern 输出的日期格式
     * @return
     */
    public static List<String> getNearMin(int count, String time, String datePattern) {
        LocalDateTime localDateTime = Optional.ofNullable(time)
                .map(o -> LocalDateTime.parse(o, DateTimeFormatter.ofPattern(DATE_FORMAT_yyyyMMddHHmmss_H)).minusMinutes(1))
                .orElseGet(() -> LocalDateTime.now().withNano(0).minusMinutes(1));
        List<String> list = new LinkedList<>();
        int i = count;
        while (i-- > 0) {
            list.add(localDateTime.toLocalTime().format(DateTimeFormatter.ofPattern(datePattern)));
            localDateTime = localDateTime.minusMinutes(1);
        }
        return list;
    }

    /**
     * 获取LocalDateTime 日期当天的开始时间，即清空时分秒
     *
     * @param time
     * @return 例如 2019-10-17 00:00:00
     */
    public static LocalDateTime getDayStart(LocalDateTime time) {
        return time.withHour(0)
                .withMinute(0)
                .withSecond(0)
                .withNano(0);
    }

    /**
     * 获取LocalDateTime 日期当天的最后一刻，即清空时分秒
     *
     * @param time
     * @return 2017-7-22 23:59:59.999999999
     */
    public static LocalDateTime getDayEnd(LocalDateTime time) {
        return time.withHour(23)
                .withMinute(59)
                .withSecond(59)
                .withNano(999999999);
    }

    /**
     * Date 日期当天的开始时间，即清空时分秒
     *
     * @param date
     * @return 例如 2019-10-17 00:00:00
     */
    public static Date getDayStart(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    public static Date getMonth(Date date,int monthNum) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH,monthNum);
        return cal.getTime();
    }

    /**
     * Date 日期当天的最后一刻，即清空时分秒
     *
     * @param date
     * @return 2017-7-22 23:59:59.999
     */
    public static Date getDayEnd(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 999);
        return cal.getTime();
    }

    /**
     * 获取当前的UTC时间字符串
     *
     * @return 2018-02-13T06:30:10
     */
    public static String getNowUTCStr() {
        return DateTimeFormatter.ISO_DATE_TIME.format(LocalDateTime.now(ZoneOffset.UTC));
    }

    /**
     * 获取当前的UTC时间Date
     *
     * @return
     */
    public static Date getNowUTCDate() {
        return convertLocalDateTimeToDate(LocalDateTime.now(ZoneOffset.UTC));
    }

    /**
     * 获取当前的时间Date
     *
     * @return date时间对象
     */
    public static Date getNowDate() {
        return convertLocalDateTimeToDate(LocalDateTime.now());
    }

    /**
     * 获取 LocalDate之间相差年月日 Period,  Period.getYears()  Period.getMonths()  Period.getDays()
     *
     * @param start
     * @param end
     * @return
     */
    public static Period getPeriod(LocalDate start, LocalDate end) {
        return Period.between(start, end);
    }

    /**
     * 获取 Date之间相差年月日 Period,  Period.getYears()  Period.getMonths()  Period.getDays()
     *
     * @param start
     * @param end
     * @return
     */
    public static Period getIntervalDays(Date start, Date end) {
        return getPeriod(convertDateToLocalDate(start), convertDateToLocalDate(end));
    }

    /**
     * 获取Date 当月最后一天的日期
     *
     * @param date
     * @return
     */
    public static Date getLastDayOfMonth(Date date) {
        return convertLocalDateTimeToDate(convertDateToLocalDateTime(date).with(TemporalAdjusters.lastDayOfMonth()));
    }

    /**
     * 获取Date 当月第一天的日期
     *
     * @param date
     * @return
     */
    public static Date getFirstDayOfMonth(Date date) {
        return convertLocalDateTimeToDate(convertDateToLocalDateTime(date).with(TemporalAdjusters.firstDayOfMonth()));
    }

    /**
     * 将Date转为LocalDateTime
     *
     * @param date
     * @return LocalDateTime
     */
    public static LocalDateTime convertDateToLocalDateTime(Date date) {
        return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
    }

    /**
     * 将Date转为 LocalDate
     *
     * @param date
     * @return LocalDate
     */
    public static LocalDate convertDateToLocalDate(Date date) {
        Instant instant = date.toInstant();
        ZoneId zone = ZoneId.systemDefault();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
        return localDateTime.toLocalDate();
    }

    /**
     * 将Date转为LocalTime
     *
     * @param date
     * @return LocalTime
     */
    public static LocalTime convertDateToLocalTime(Date date) {
        Instant instant = date.toInstant();
        ZoneId zone = ZoneId.systemDefault();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
        return localDateTime.toLocalTime();
    }


    /**
     * 将LocalDateTime 转为Date
     *
     * @param localDateTime
     * @return Date
     */
    public static Date convertLocalDateTimeToDate(LocalDateTime localDateTime) {
        ZoneId zone = ZoneId.systemDefault();
        Instant instant = localDateTime.atZone(zone).toInstant();
        return Date.from(instant);
    }

    /**
     * 将LocalDate转为Date
     *
     * @param localDate
     * @return Date
     */
    public static Date convertLocalDateToDate(LocalDate localDate) {
        ZoneId zone = ZoneId.systemDefault();
        Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
        return Date.from(instant);
    }

    /**
     * 得到当前utc时间,并格式化为 pattern  字符串
     *
     * @return
     */
    public static String convertNowUtcToString(String pattern) {
        Date utcNowDate = getNowUTCDate();
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(utcNowDate);
    }

    /**
     * 将本地Date日期转化为UTC日期
     *
     * @param date
     * @return
     */
    public static Date convertDateToUTC(Date date) {
        LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC);
        return Date.from(localDateTime.toInstant(ZoneOffset.UTC));
    }

    /**
     * utc时间字符串转成本地时区Date
     *
     * @param utcTime       例如 2019-10-17T10:10:10.888888888Z
     * @param utcTimeFormat 例如 yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'
     * @return Date    2019-10-17T18:10:10.888888888Z
     */
    public static Date convertUtcStrToLocalZoneDate(String utcTime, String utcTimeFormat) {
        try {
            LocalDateTime ldt = LocalDateTime.parse(utcTime, DateTimeFormatter.ofPattern(utcTimeFormat));
            ZonedDateTime zdt = ldt.atZone(ZoneId.of("UTC"));
            Date date = Date.from(zdt.toInstant());
            return date;
        } catch (Exception e) {
            logger.error("convertUtcStrToLocalZoneDate utcTime {},utcTimeFormat {} error", utcTime, utcTimeFormat, e);
            return null;
        }
    }

    /**
     * 将LocalDateTime 格式化为pattern 格式的字符串
     *
     * @param time    要格式化的LocalDateTime
     * @param pattern 字符串的格式
     * @return
     */
    public static String formatTime(LocalDateTime time, String pattern) {
        return time.format(DateTimeFormatter.ofPattern(pattern));
    }

    /**
     * 将当前时间转化为指定格式字符串
     *
     * @param pattern 日期格式
     * @return
     */
    public static String formatNow(String pattern) {
        return formatTime(LocalDateTime.now(), pattern);
    }


    /**
     * 格式化日期格式
     *
     * @param date
     * @param pattern
     * @return
     */
    public static String formatDateToString(Date date, String pattern) {
        String dateStr = "";
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
            dateStr = simpleDateFormat.format(date);
        } catch (Exception e) {
            logger.error("formatDateToString has error", e);
        }
        return dateStr;
    }

    /**
     * 合并LocalDate LocalTime 为 LocalDateTime
     *
     * @param localDate
     * @param localTime
     * @return
     */
    public static LocalDateTime mergeLocalDateAndTime(LocalDate localDate, LocalTime localTime) {
        return LocalDateTime.of(localDate, localTime);
    }


    /**
     * 在指定日期 time 的基础上，添加指定 number 的 时间单位
     *
     * @param time
     * @param number 可正可负
     * @param field  为 ChronoUnit，such as ChronoUnit.DAYS ,ChronoUnit.MONTHS
     * @return
     */
    public static LocalDateTime plus(LocalDateTime time, long number, TemporalUnit field) {
        return time.plus(number, field);
    }

    /**
     * 在指定日期 time 的基础上，减去指定 number 的 时间单位
     *
     * @param time
     * @param number 可正可负
     * @param field  为 ChronoUnit，such as ChronoUnit.DAYS ,ChronoUnit.MONTHS
     * @return
     */
    public static LocalDateTime minu(LocalDateTime time, long number, TemporalUnit field) {
        return time.minus(number, field);
    }

    /**
     * 获取两个日期的差  field参数为ChronoUnit.*
     *
     * @param startTime
     * @param endTime
     * @param field     单位(年月日时分秒)
     * @return 跟startTime ,endTime 大小有关，为正数或者负数
     */
    public static long betweenTwoTime(LocalDateTime startTime, LocalDateTime endTime, ChronoUnit field) {
        Period period = Period.between(LocalDate.from(startTime), LocalDate.from(endTime));
        if (field == ChronoUnit.YEARS) {
            return period.getYears();
        }
        if (field == ChronoUnit.MONTHS) {
            return period.getYears() * 12 + period.getMonths();
        }
        return field.between(startTime, endTime);
    }

    /**
     * 将date加减 plusMinutes 分钟数
     *
     * @param date        日期
     * @param plusMinutes 要加减加的分钟数，通过正负数处理加减
     * @return 新的日期
     */
    public static Date addMinutes(Date date, Long plusMinutes) {
        LocalDateTime dateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
        LocalDateTime newDateTime = dateTime.plusMinutes(plusMinutes);
        return Date.from(newDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

    /**
     * 对日期加减月数
     *
     * @param date   日期
     * @param months 月数（可为负数）
     * @return
     */
    public static Date addDateWithMonths(Date date, int months) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, months);
        return calendar.getTime();
    }

    /**
     * 对日期加减天数
     *
     * @param date
     * @param days 天数（可为负数）
     * @return
     */
    public static Date addDateWithDays(Date date, int days) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, days);
        return calendar.getTime();
    }

    /**
     * 对日期加减小时
     *
     * @param date  当前日期
     * @param hours 小时数（可为负）
     * @return
     */
    public static Date addDateWithHours(Date date, int hours) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, hours);
        return calendar.getTime();
    }

    /**
     * 判断 ISO_DATE 格式的 str 日期是否为闰年
     * ISO_DATE such as '2011-12-03' or '2011-12-03+01:00'
     *
     * @param str
     * @return
     */
    public static boolean isLeapYear(String str) {
        LocalDate localDate = parseLocalDate(str);
        return localDate.isLeapYear();
    }

    /**
     * 判断Date是否为闰年
     *
     * @param date
     * @return
     */
    public static boolean isLeapYear(Date date) {
        return convertDateToLocalDate(date).isLeapYear();
    }

    /**
     * 校验 日期字符串是否为 pattern 格式
     *
     * @param str
     * @param pattern
     * @return
     */
    public static boolean validDateFormat(String str, String pattern) {
        boolean flag = true;
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        try {
            format.setLenient(false);
            format.parse(str);
        } catch (ParseException e) {
            flag = false;
        }
        return flag;
    }


    /**
     * 比较日期字符串的大小，按照format格式解析比对，返回比对结果
     *
     * @param start
     * @param end
     * @param format
     * @return 1 start > end , -1 start < end , 0 start = end or exception
     */
    public static int compareDate(String start, String end, String format) {
        if (StringUtils.isEmpty(format)) {
            format = "yyyy-MM-dd";
        }
        SimpleDateFormat df = new SimpleDateFormat(format);
        try {
            Date dt1 = df.parse(start);
            Date dt2 = df.parse(end);

            if (dt1.after(dt2)) {
                return 1;
            } else if (dt1.before(dt2)) {
                return -1;
            } else {
                return 0;
            }
        } catch (Exception e) {
            logger.error("compareDate error", e);
        }
        return 0;
    }

    /**
     * 字符串日期转换格式
     *
     * @param dataStr    待转换日期字符串
     * @param formatFrom 转换前格式
     * @param formatTo   转换后格式
     * @return
     */
    public static String changDataFormat(String dataStr, String formatFrom, String formatTo) {
        if (org.apache.commons.lang3.StringUtils.isBlank(dataStr)) {
            return dataStr;
        }
        try {
            SimpleDateFormat simpleFormatFrom = new SimpleDateFormat(formatFrom);
            return new SimpleDateFormat(formatTo).format(simpleFormatFrom.parse(dataStr));
        } catch (ParseException e) {
            logger.error("{} from {} to {} error!", dataStr, formatFrom, formatTo, e);
        }
        return dataStr;
    }

    private static void validStringParam(String... params) {
        for (String param : params) {
            if (StringUtils.isEmpty(param)) {
                throw new NullPointerException();
            }
        }
    }

    public static long utcToLong(String utcTimeWithZ) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
            df.setTimeZone(TimeZone.getTimeZone("UTC"));
            Date parse = df.parse(utcTimeWithZ);
            return parse.getTime();
        } catch (Exception e) {
            return 0;
        }
    }

    public static String gmt8ToUtcStr(String date) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
            Date parsed = sdf.parse(date);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
            simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            return simpleDateFormat.format(parsed);
        } catch (Exception e) {
            return "";
        }
    }


    /**
     * 计算两个日期相差的  天数、月数、年数
     *
     * @param fromDate
     * @param toDate
     * @return
     */
    public static DayCompareBean dayCompare(Date fromDate, Date toDate) {
        return dayCompare(fromDate.getTime(), toDate.getTime());
    }

    public static DayCompareBean dayCompare(long fromDate, long toDate) {
        Calendar from = Calendar.getInstance();
        from.setTimeInMillis(fromDate);
        Calendar to = Calendar.getInstance();
        to.setTimeInMillis(toDate);

        int fromYear = from.get(Calendar.YEAR);
        int fromMonth = from.get(Calendar.MONTH);
        int toYear = to.get(Calendar.YEAR);
        int toMonth = to.get(Calendar.MONTH);
        int year = toYear - fromYear;
        int month = toYear * 12 + toMonth - (fromYear * 12 + fromMonth);
        int day = (int) ((to.getTimeInMillis() - from.getTimeInMillis() / (24 * 3600 * 1000)));
        return DayCompareBean.builder().day(day).month(month).year(year).build();
    }


}
